package org.example.game.history;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/06/08 23:22
 */
public class Solution100331 {

    public static void main(String[] args) {
        System.out.println(new Solution100331().maximumLength(new int[]{1,2,1,1,3}, 2));
    }

    public int maximumLength(int[] nums, int k) {
        if(nums.length == 1){
            return 1;
        }

        int count = 0;
        int lastIndex = 0;
        for (int i = 0; i < nums.length-1; i++) {


            if(nums[i] != nums[i+1]){
                count++;
            }

            if(count >= k){
                lastIndex = Math.max(1, i);
                break;
            }


        }

        return lastIndex + 1 == nums.length ? lastIndex : lastIndex + 1;
    }

}
